package sort;

/**
 * @description: 选择排序 O(n2)
 * @title: SelectSort
 * @author: zp
 * @date: 2021/11/14 20:23
 */
public class SelectSort extends BaseSort {
    public static void main(String[] args) {
        int count = 100000;
        Integer[] ints = new Integer[count];
        for (int i = 0; i < count; i++) {
            ints[i] = (int) (Math.random() * count);
        }
        long start = System.currentTimeMillis();
        sort(ints);
        long end = System.currentTimeMillis();
        System.out.println((end - start));
    }

    public static void sort(Comparable[] ints) {
        int length = ints.length;
        //（从小到大）取第一个和全部的比 把最小的放在第一位 第二个和n-1个数据比较找到第二个 以此类推 把整个数组都有序化
        for (int i = 0; i < length - 1; i++) {
            for (int j = i; j < length; j++) {
                if (more(ints[i], ints[j])) {
                    exch(ints, i, j);
                }
            }
        }
    }
}
